package com.sharedprint.system.user.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;


import org.slf4j.spi.LocationAwareLogger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.sharedprint.system.user.pojo.User;
import com.sharedprint.system.user.service.UserService;
import com.sharedprint.util.Token;

@Controller
@RequestMapping("/api/user")

public class UserController {
private static final Logger logger=Logger.getLogger("UserController");
@Autowired
private UserService userService;
/**
 *   /api/user/login

 */
@RequestMapping("/login")
@ResponseBody
public  Map<String, Object> login(HttpServletRequest req){
	String username = req.getParameter("username");
	String upwd = req.getParameter("upwd");
	
//	int result=0;
	System.out.println("username="+username+"upwd="+upwd);
	

	Map<String, Object> resultMap=new HashMap<String, Object>();
	resultMap.put("success", "0");
	if (username!=null && !"".equals(username.trim())
			&& upwd!=null && !"".equals(upwd.trim())) {
	Map<String , Object>searchMap=new HashMap<String, Object>();
	searchMap.put("userName", username);
	searchMap.put("upwd", upwd)	;
	List<Map<String , Object>> userList=userService.findUserList(searchMap);
	if (userList!=null) {
		Map<String, Object>usermap=userList.get(0);
		String token=Token.getTokenString(req.getSession());
		 resultMap.put("success", "1");
         resultMap.put("token", token);
         resultMap.put("userId", usermap.get("uid"));
         resultMap.put("trueName", usermap.get("trueName"));
         resultMap.put("userName", username);
         resultMap.put("headpic", usermap.get("uheadpic"));

	}
	}
	return resultMap;

}


}
